<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS测试</title>
<#include "/include/common.ftl">
</head>
<body>
<input type="button" value="提交" id="btnArray"/>
<input type="checkbox" name="ids" value="1"/>
<input type="checkbox" name="ids" value="2"/>
<input type="checkbox" name="ids" value="3"/>
<input type="checkbox" name="ids" value="4"/>
</body>
<script>
    $(function ($) {

        /**
         * 测试ajax提交数组
         */
        $("#btnArray").click(function () {
            var $checkedIds = $("input[name='ids']:checked");
            alert(typeof  $checkedIds);

            //方式一
            $.ajax({
                type: "POST",
                url: "array.htm",
                data: $checkedIds.serialize(),
                dataType: "json",
                async: false,
                success: function (ret) {
                    alert("方式一返回：" + ret);
                }
            });

            alert("开始方式二提交");
            $.ajax({
                type: "POST",
                url: "array.htm",
                traditional: "true",
                data: {"ids":[8,9]},
                dataType: "json",
                async: false,
                success: function (ret) {
                    alert("方式二返回："+ret);
                }
            });
        });
    });
</script>
</html>